package com.sustcoder.blog.Blog09;

import com.sustcoder.blog.Blog09.model.MapBean;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lenovo on 2017/9/27.
 */
public class Map2Bean {
    public static void main(String[] args) {
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("osno",111111);
        map.put("filename","");
        Object obj=map2Bean(map,MapBean.class);
        MapBean osFileInfo=(MapBean)obj;
        System.out.println(osFileInfo.getFilename());
        System.out.println(osFileInfo.getOsno());

    }
    public static  Object map2Bean(Map<String,Object> map,Class<?> beanClass) {
        try{
            Object obj=beanClass.newInstance();
            org.apache.commons.beanutils.BeanUtils.populate(obj, map);
            return  obj;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }




}
